﻿package com.zkingsoft.services.pc.impl;

import com.zkingsoft.services.pc.PcMenuFoodService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.pc.PcMenuFood;
import com.zkingsoft.dao.pc.PcMenuFoodDao;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.util.ModelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-03-14 14:37
 */
@Service("pcMenuFoodService")
public class  PcMenuFoodServiceImpl implements    PcMenuFoodService  {

	
	@Autowired
	private PcMenuFoodDao pcMenuFoodDao;
	
	
	@Override
	public int add(PcMenuFood pcMenuFood){
		
		return pcMenuFoodDao.insert(pcMenuFood);
		
	}
	
	@Override
	public int batchAdd(List<PcMenuFood>  pcMenuFoodList) {
		int num = 0;

		int c = 10000;
		int size = pcMenuFoodList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= pcMenuFoodList.size() ? pcMenuFoodList.size() : end;
			List<PcMenuFood> insertList = pcMenuFoodList.subList(begin, end);
			num += pcMenuFoodDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(PcMenuFood oldPcMenuFood
	,PcMenuFood newPcMenuFood){
	
		if (!ModelUtils.isModified(oldPcMenuFood, newPcMenuFood)) {
			return 1;
		}
		Map<String, Object> modifyMap=null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldPcMenuFood, newPcMenuFood);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("mefId", oldPcMenuFood.getMefId());
			pcMenuFoodDao.updateByMap(modifyMap);
		}
		return 1;
	}
	
	@Override
	public int modifyByModel(PcMenuFood pcMenuFood){
	
		return pcMenuFoodDao.updateByModel(pcMenuFood);
	
	}
	
	
	
	@Override
	public int remove(List<Long> list){
	
		return pcMenuFoodDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(Long mefId){
	
		return pcMenuFoodDao.deleteById(mefId);
	
	}
	
	@Override
	public int removeByModel(PcMenuFood pcMenuFood){
	
		return pcMenuFoodDao.deleteByModel(pcMenuFood);
	
	}
	
	
	@Override
	public List<PcMenuFood> findInPage(PcMenuFood pcMenuFood,  PaginationVO pageVo){
	
		return pcMenuFoodDao.selectInPage(pcMenuFood , pageVo);
	
	}
	
	@Override
	public List<PcMenuFood> findByModel(PcMenuFood pcMenuFood){
	
		return pcMenuFoodDao.selectByModel(pcMenuFood);
	
	}
	
	@Override
	public int  findTotal(PcMenuFood pcMenuFood){
	
		return pcMenuFoodDao.selectTotalRecord(pcMenuFood);
	
	}
	
	@Override
	public PcMenuFood  findById(Long mefId){
	
		return pcMenuFoodDao.selectById(mefId);
	
	}

   	
	
	
}